package com.hsnn.medstgmini.trading.pur.model.form;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class OrderPack {

	private String orderPackId; // 订单包号
	private Date submitDatetime; // 订单提交时间
	private Date orderConfirmTime; // 订单确认时间
	private List<OrderDetail> orderDetailList; // 订单明细列表
	private String orderDetails; // json格式订单明细列表
	private String recpCode;	//	验收单号

	public String getOrderPackId() {
		return orderPackId;
	}

	public void setOrderPackId(String orderPackId) {
		this.orderPackId = orderPackId;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getSubmitDatetime() {
		return submitDatetime;
	}

	public void setSubmitDatetime(Date submitDatetime) {
		this.submitDatetime = submitDatetime;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getOrderConfirmTime() {
		return orderConfirmTime;
	}

	public void setOrderConfirmTime(Date orderConfirmTime) {
		this.orderConfirmTime = orderConfirmTime;
	}

	public List<OrderDetail> getOrderDetailList() {
		return orderDetailList;
	}

	public void setOrderDetailList(List<OrderDetail> orderDetailList) {
		this.orderDetailList = orderDetailList;
	}

	public String getOrderDetails() {
		return orderDetails;
	}

	public void setOrderDetails(String orderDetails) {
		if (StringUtils.isNotBlank(orderDetails)) {
			Type type = new TypeToken<List<OrderDetail>>() {
			}.getType();
			Gson gson = new Gson();
			orderDetailList = gson.fromJson(orderDetails, type);
		}
		this.orderDetails = orderDetails;
	}

	public String getRecpCode() {
		return recpCode;
	}

	public void setRecpCode(String recpCode) {
		this.recpCode = recpCode;
	}

	@Override
	public String toString() {
		return "OrderPack [orderPackId=" + orderPackId + ", submitDatetime="
				+ submitDatetime + ", orderConfirmTime=" + orderConfirmTime
				+ ", orderDetailList=" + orderDetailList + ", orderDetails="
				+ orderDetails + ", recpCode=" + recpCode + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((orderConfirmTime == null) ? 0 : orderConfirmTime.hashCode());
		result = prime * result
				+ ((orderDetailList == null) ? 0 : orderDetailList.hashCode());
		result = prime * result
				+ ((orderDetails == null) ? 0 : orderDetails.hashCode());
		result = prime * result
				+ ((orderPackId == null) ? 0 : orderPackId.hashCode());
		result = prime * result
				+ ((recpCode == null) ? 0 : recpCode.hashCode());
		result = prime * result
				+ ((submitDatetime == null) ? 0 : submitDatetime.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrderPack other = (OrderPack) obj;
		if (orderConfirmTime == null) {
			if (other.orderConfirmTime != null)
				return false;
		} else if (!orderConfirmTime.equals(other.orderConfirmTime))
			return false;
		if (orderDetailList == null) {
			if (other.orderDetailList != null)
				return false;
		} else if (!orderDetailList.equals(other.orderDetailList))
			return false;
		if (orderDetails == null) {
			if (other.orderDetails != null)
				return false;
		} else if (!orderDetails.equals(other.orderDetails))
			return false;
		if (orderPackId == null) {
			if (other.orderPackId != null)
				return false;
		} else if (!orderPackId.equals(other.orderPackId))
			return false;
		if (recpCode == null) {
			if (other.recpCode != null)
				return false;
		} else if (!recpCode.equals(other.recpCode))
			return false;
		if (submitDatetime == null) {
			if (other.submitDatetime != null)
				return false;
		} else if (!submitDatetime.equals(other.submitDatetime))
			return false;
		return true;
	}

	
}
